using System.Windows.Forms;
using Vin.Event;
using Vin.Win32.EventArgs;

namespace Vin.Win32;

public static class VinWin32App
{
    #region 使用Win32App

    public static void InstallWin32App(this Form form)
    {
        InstallWin32App(form.Handle);
    }

    public static void UninstallWin32App(this Form form)
    {
        UninstallWin32App(form.Handle);
    }

    public static void InstallWin32App(IntPtr hWnd)
    {
        // 添加剪贴板监听
        VinUser32.AddClipboardFormatListener(hWnd);
    }

    public static void UninstallWin32App(IntPtr hWnd)
    {
        // 移除剪贴板监听
        VinUser32.RemoveClipboardFormatListener(hWnd);
    }

    #endregion

    public static void HandleWndProc(Message msg)
    {
        // 剪贴板内容更改
        ClipboardUpdate(msg);
    }


    public static void ClipboardUpdate(Message msg)
    {
        switch (msg.Msg)
        {
            // 剪贴板的内容发生更改时发送
            case (int)VinUser32.ClipboardMsg.WM_CLIPBOARDUPDATE:
                VinEventManager.Fire<ClipboardUpdateEventArg>(null, new ClipboardUpdateEventArg());
                break;
        }
    }
}